(0, require("../common/component").VantComponent)({
    props: {
        title: String,
        value: String,
        loading: Boolean,
        itemHeight: {
            type: Number,
            value: 44
        },
        visibleItemCount: {
            type: Number,
            value: 5
        },
        columnsNum: {
            type: [ String, Number ],
            value: 3
        },
        areaList: {
            type: Object,
            value: {}
        }
    },
    data: {
        pickerValue: [ 0, 0, 0 ],
        columns: []
    },
    computed: {
        displayColumns: function() {
            var t = this.data, e = t.columns, i = void 0 === e ? [] : e, s = t.columnsNum;
            return i.slice(0, +s);
        }
    },
    watch: {
        value: function(t) {
            this.code = t, this.setValues();
        },
        areaList: "setValues"
    },
    methods: {
        onCancel: function() {
            this.$emit("cancel", {
                values: this.getValues(),
                indexs: this.getIndexs()
            });
        },
        onConfirm: function() {
            this.$emit("confirm", {
                values: this.getValues(),
                indexs: this.getIndexs()
            });
        },
        onChange: function(t) {
            var e = t.detail.value, i = this.data, s = i.pickerValue, n = i.displayColumns, a = s.findIndex(function(t, i) {
                return t !== e[i];
            }), u = n[a];
            a < 0 || e[a] < 0 || !u[e[a]] || (this.code = u[e[a]].code, this.setValues(), this.$emit("change", {
                picker: this,
                values: this.getValues(),
                index: a
            }));
        },
        getList: function(t, e) {
            var i = [];
            if ("province" !== t && !e) return i;
            var s = this.data.areaList && this.data.areaList[t + "_list"] || {};
            return i = Object.keys(s).map(function(t) {
                return {
                    code: t,
                    name: s[t]
                };
            }), e && (i = i.filter(function(t) {
                return 0 === t.code.indexOf(e);
            })), i;
        },
        getIndex: function(t, e) {
            var i = "province" === t ? 2 : "city" === t ? 4 : 6, s = this.getList(t, e.slice(0, i - 2));
            e = e.slice(0, i);
            for (var n = 0; n < s.length; n++) if (s[n].code.slice(0, i) === e) return n;
            return 0;
        },
        setValues: function() {
            var t = this.code || this.data.areaList && Object.keys(this.data.areaList.county_list || {})[0] || "", e = this.getList("province"), i = this.getList("city", t.slice(0, 2));
            this.setData({
                "columns[0]": e,
                "columns[1]": i
            }), i.length && "00" === t.slice(2, 4) && (t = i[0].code), this.setData({
                "columns[2]": this.getList("county", t.slice(0, 4)),
                pickerValue: [ this.getIndex("province", t), this.getIndex("city", t), this.getIndex("county", t) ]
            });
        },
        getValues: function() {
            var t = this.data, e = t.displayColumns, i = void 0 === e ? [] : e, s = t.pickerValue, n = void 0 === s ? [] : s;
            return i.map(function(t, e) {
                return t[n[e]];
            });
        },
        getIndexs: function() {
            var t = this.data, e = t.pickerValue, i = t.columnsNum;
            return e.slice(0, i);
        },
        reset: function() {
            this.code = "", this.setValues();
        }
    }
});